package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.ScenicDetail;
import cn.wolfcode.luowowo.article.domain.ScenicRegion;
import cn.wolfcode.luowowo.article.mapper.ScenicDetailMapper;
import cn.wolfcode.luowowo.article.mapper.ScenicRegionMapper;
import cn.wolfcode.luowowo.article.service.IScenicRegionService;
import com.alibaba.dubbo.config.annotation.Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ScenicRegionServiceImpl implements IScenicRegionService {
    @Autowired
    private ScenicRegionMapper scenicRegionMapper;
    @Autowired
    private ScenicDetailMapper scenicDetailMapper;

    @Override
    public List<ScenicRegion> listByDestId(Long destId) {
        //1、获取region是对象
        List<ScenicRegion> regions = scenicRegionMapper.selectByDestId(destId);
        //2、遍历,获取子景点
        for (ScenicRegion region : regions) {
            List<ScenicDetail> details=scenicDetailMapper.selectByRefIds(region.getRefIds());
            for (ScenicDetail detail : details) {
                region.getScenicDetails().add(detail);
            }
            String[] split = region.getCoverUrl().split(",");
            for (String coverUrl : split) {
               region.getCoverUrls().add(coverUrl);
            }
        }
        return regions;
    }

    @Override
    public ScenicRegion getRegion(Long regionId) {
        return scenicRegionMapper.selectByPrimaryKey(regionId);
    }
}
